package cz.mff.kusad5am.hb.ws;

import java.util.List;

import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;

import cz.mff.kusad5am.hb.schema.list.Hostel;
import cz.mff.kusad5am.hb.schema.roomlist.RoomType;
import cz.mff.kusad5am.hb.service.ListOfRoomsWorker;
import cz.mff.kusad5am.hb.service.ReservationWorker;

public class CancellationEndpoint extends AbstractJDomPayloadEndpoint {

	private final ReservationWorker worker;
	
	public CancellationEndpoint(ReservationWorker worker) {
		this.worker = worker;
	}
	
	
	@Override
	protected Element invokeInternal(Element requestElement) throws Exception {
		
		System.out.println("Cancellation called..");
//		Namespace ns = requestElement.getNamespace();
//		String nsp = ns.getPrefix();
//		String country = XPath.newInstance("//"+nsp+":RoomListRequest/@Country").valueOf(requestElement);
//		String city = XPath.newInstance("//"+nsp+":RoomListRequest/@City").valueOf(requestElement);
//		String start = XPath.newInstance("//"+nsp+":RoomListRequest/@arrivalDate").valueOf(requestElement);
//		String guests = XPath.newInstance("//"+nsp+":RoomListRequest/@numberOfGuests").valueOf(requestElement);
//		String nights = XPath.newInstance("//"+nsp+":RoomListRequest/@numerOfNights").valueOf(requestElement);
//		String hostelId = XPath.newInstance("//"+nsp+":RoomListRequest/"+nsp+":ChosenHostel/@id").valueOf(requestElement);
//		
//		worker.createReservation();
//		Element response = createResponse(types, country, city, start, guests, nights, hostel, ns);
//		return response;
		return requestElement;
	}
	
	private Element createResponse(List<RoomType> types, String country, String city, String start, String guests, String nights, Hostel hostel, Namespace tns) {
//		Element response = new Element("HostelListResponse");
//		response.setNamespace(tns);
//		response.setAttribute("Country", country);
//		response.setAttribute("City", city);
//		response.setAttribute("arrivalDate", start);
//		response.setAttribute("numberOfGuests", guests);
//		response.setAttribute("numberOfNights", nights);
//		
//		Element hostelWithRooms = new Element("HostelWithRooms");
//		hostelWithRooms.setNamespace(tns);
//		hostelWithRooms.setAttribute("name", hostel.getName());
//		hostelWithRooms.setAttribute("id", new Integer(hostel.getId()).toString());
//		hostelWithRooms.setAttribute("priceDormFrom", hostel.getPriceDormFrom());
//		hostelWithRooms.setAttribute("pricePrivateFrom", hostel.getPricePrivateFrom());
//		hostelWithRooms.setAttribute("Country", hostel.getCountry());
//		hostelWithRooms.setAttribute("City", hostel.getCity());
//		hostelWithRooms.setAttribute("Address", hostel.getAddress());
//		hostelWithRooms.setAttribute("ZipCode", hostel.getZipCode());
//		response.setContent(hostelWithRooms);
//		
//		for(RoomType r: types) {
//			Element child = new Element("RoomType");
//			child.setNamespace(tns);
//			child.setAttribute("isPrivate", r.getIsPrivate());
//			child.setAttribute("bedCount", r.getBedCount());
//			child.setAttribute("hasPrivateShower", r.getHasPrivateShower());
//			child.setAttribute("note", r.getNote());
//			child.setAttribute("priceForNightForPerson", r.getPriceForNightForPerson());
//			child.setAttribute("id", r.getId());
//			hostelWithRooms.addContent(child);
//		}
//		return response;
		return null;
	}
}
